package com.yueqian.service.impl;

import com.yueqian.dao.AccountDao;
import com.yueqian.domain.Account;
import com.yueqian.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service("accountService")
//@Transactional
public class AccountServiceImpl implements AccountService {

    @Autowired
    private AccountDao accountDao;

    @Override
    public void saveAccount(Account account) throws Exception {
        System.out.println("AccountServiceImpl---saveAccount");
        System.out.println("accountDao: " + accountDao);
        accountDao.saveAccount(account);
    }

    @Override
    public List<Account> findAll() throws Exception{
        //System.out.println("accountDao: " + accountDao);
        System.out.println("AccountServiceImpl---findAll");
        List<Account> list = accountDao.findAll();
        //System.out.println(list);
        return list;
    }

    @Override
    public void transfer() throws Exception {
        Account account1 = accountDao.findById(1);
        Account account3 = accountDao.findById(3);
        account1.setMoney(account1.getMoney()-100);
        account3.setMoney(account3.getMoney()+100);
        accountDao.updateAccount(account1);
        int a = 10/0;
        accountDao.updateAccount(account3);
    }
}
